<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
    <meta name="format-detection" content="telephone=no" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>公司信息</title>
	<style>
		body {
			font-family: Arial, sans-serif;
			background-color: #F5F5F5;
			margin: 0;
			padding: 0;
		}

		.container {
			max-width: 600px;
			margin: 0 auto;
			padding: 20px;
			background-color: #FFFFFF;
			box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.1);
		}

		h1 {
			font-size: 24px;
			font-weight: bold;
			color: #333333;
			margin-top: 0;
			margin-bottom: 10px;
		}

		p {
			font-size: 16px;
			color: #666666;
			margin-top: 0;
			margin-bottom: 10px;
		}

		ul {
			list-style-type: none;
			padding: 0;
			margin: 0;
		}

		li {
			font-size: 16px;
			color: #666666;
			margin-bottom: 10px;
		}

		li:last-child {
			margin-bottom: 0;
		}

        .copy-button {
			padding: 10px;
			background-color: #4CAF50;
			color: #FFFFFF;
			border: none;
			border-radius: 5px;
			cursor: pointer;
			transition: all 0.3s ease;
            margin-left: 10px;
		}

		.copy-button:hover {
			background-color: #3E8E41;
		}
		.buttons {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			/* align-items: center; */
			margin-top: 20px;
            align-items: stretch;
		}

        .button {
            flex: 1;
			padding: 10px;
			background-color: #4CAF50;
			color: #FFFFFF;
			border: none;
			border-radius: 5px;
			cursor: pointer;
			transition: all 0.3s ease;
            flex-grow: 1;
		    flex-shrink: 0;
		}

        .button + .button {
            margin-left: 10px;
        }
		.button:hover {
			background-color: #3E8E41;
		}
        #notice{
            padding: 10px;
            text-align: center;
        }
        .numbers {
            align-items: right;
            text-align: right;
            /* float: right; */
            padding-bottom: 20px;
        }


	</style>
</head>
<body>

	<div class="container">
        <div class="numbers">
            今日处理：{$today_handle}
            剩余：{$remain_count}
        </div>
		<h1>{$company.company_name}</h1>
		<ul>
			<li>法人姓名: {$company.owner_name|default=""}</li>
			<li>地址: {$company.address|default=""}</li>
			<li>联系方式: <span id="phone-number">{$company.phone|default=""}</span><button class="copy-button" onclick="copyPhoneNumber('{$company.phone|default=""}')">复制</button></li>
			<li>其他联系方式:</li>

            {volist name="company.other_phone" id="item" key="key"}
			    <li> <span id="phone-number">{$item|default=""}</span><button class="copy-button" onclick="copyPhoneNumber('{$item|default=""}')">复制</button></li>
            {/volist}
            <li>营业范围: {$company.operate_range|default=""|raw}</li>
		</ul>
        <div class="buttons">
            <button class="button" id="notSuitable" style="background-color:#E6A23C;" onclick="notSuitable()">不合适</button>
            <button class="button" id="nextBtn" style="background-color: #67C23A;" onclick="next()">下一个</button>

            <!-- <button class="button" onclick="addToContacts()">保存至通讯录</button> -->
        </div>
	</div>
    <p id="notice"></p>
</body>

<script>


    var id = '{$company.id|default="0"}';

    function copyPhoneNumber(phoneNumber) {
        // 获取手机号码
        // var phoneNumber = document.getElementById("phone-number").innerHTML;
        // 创建一个临时文本输入框
        var tempInput = document.createElement("input");
        tempInput.style = "position: absolute; left: -1000px; top: -1000px";
        tempInput.value = phoneNumber;
        document.body.appendChild(tempInput);
        // 选中文本并复制
        tempInput.select();
        document.execCommand("copy");
        // 删除临时文本输入框
        document.body.removeChild(tempInput);

        // 提示用户已复制
        document.getElementById("notice").innerHTML = "已复制手机号码: " + phoneNumber;


		var userAgent = navigator.userAgent.toLowerCase(); 

		// if(userAgent.indexOf("iphone") != -1 || userAgent.indexOf("ipad") != -1){
			
		// } else if(userAgent.indexOf("android") != -1){
		// // Android
		// } else{
		// // Other
		// }
		window.location.href = "weixin://";


		
    }

	function next() {
		// 发起网络请求


        // 获取按钮元素
        const nextBtn = document.getElementById('nextBtn');

        // 禁用按钮并添加加载状态
        nextBtn.disabled = true;
        nextBtn.innerHTML = '加载中...';

		var xhr = new XMLHttpRequest();
		xhr.open("POST", "/index/company/operate", true);
		xhr.setRequestHeader("Content-type", "application/json");
		xhr.onreadystatechange = function() {
			if (xhr.readyState === 4 && xhr.status === 200) {
				document.getElementById("notice").innerHTML = "操作成功，正在跳转...";
                history.go(0);
			}
            nextBtn.disabled = false;
            nextBtn.innerHTML = '下一个';

		};
		xhr.send(JSON.stringify({status: "2", id: id}));
	}

	function notSuitable() {
		// 发起网络请求
        const notSuitable = document.getElementById('notSuitable');
        // 禁用按钮并添加加载状态
        notSuitable.disabled = true;
        notSuitable.innerHTML = '加载中...';
		var xhr = new XMLHttpRequest();
		xhr.open("POST", "/index/company/operate", true);
		xhr.setRequestHeader("Content-type", "application/json");
		xhr.onreadystatechange = function() {
			if (xhr.readyState === 4 && xhr.status === 200) {
                document.getElementById("notice").innerHTML = "操作成功，正在跳转...";
                history.go(0);
			}
            notSuitable.disabled = false;
            notSuitable.innerHTML = '不合适';
		};
		xhr.send(JSON.stringify({status: "3", id: id}));
	}

	function addToContacts() {
		// 获取公司信息
		var companyName = '{$company.company_name|default=""}';;
		var companyAddress = '{$company.address|default=""}';;
		var phoneNumber = '{$company.phone|default=""}';

		// 如果浏览器支持Contacts API
		if (navigator.contacts) {
			// 创建联系人对象
			var contact = navigator.contacts.create();
			// 设置联系人属性
			var name = new ContactName();
			name.formatted = companyName;
			contact.name = name;
			var addresses = [];
			var address = new ContactAddress();
			address.type = "work";
			address.formatted = companyAddress;
			addresses.push(address);
			contact.addresses = addresses;
			var phoneNumbers = [];
			var phone = new ContactField("work", phoneNumber, true);
			phoneNumbers.push(phone);
			contact.phoneNumbers = phoneNumbers;
			// 保存联系人
			contact.save(function() {
				alert("已保存至通讯录");
			}, function() {
				alert("保存失败");
			});
		} else {
			alert("浏览器不支持Contacts API");
		}
	}
</script>

</html>
